package com.jymj.controller;

import com.jymj.entity.Analysis.*;
import com.jymj.entity.SysUserEntity;
import com.jymj.entity.dto.ReportDto;
import com.jymj.entity.dto.ScorebarDto;
import com.jymj.entity.landmanage.JournalEntity;
import com.jymj.entity.landmanage.PointRecordEntity;
import com.jymj.entity.landmanage.ScoreEntity;
import com.jymj.service.AnalysisService;
import com.jymj.service.EnviorSupvsService;
import com.jymj.utils.R;
import com.jymj.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by ${lc} on 2021/2/3.
 */
@RestController
@RequestMapping("/analysis")
public class AnalysisController {
    @Autowired
    /**
     * 人居环境整改情况统计
     */
    private AnalysisService analysisService;
    @Autowired
    private EnviorSupvsService enviorSupvsService;

    /**
     * 人居环境整改情况统计表
     * 附录3
     * @param date
     * @return
     */
    @PostMapping("/queryRjhjzgtj")
    public R queryRjhjzgtj(String date){
        return R.ok().put("data",analysisService.selectRjhjzgtj(date));
    }

    /**
     * 各乡镇突出问题点位汇总表
     * @param date "yyyy-MM"
     * @return
     */
    @PostMapping("/queryZdwt")
    public R monthlySummaryPoint(String date){
        List<MonthlySummaryPoint> monthlySummaryPoints = analysisService.monthlySummaryPoint(date);
        return R.ok().put("data",monthlySummaryPoints);
    }

    /**
     * 人居环境检查不合格村庄明细表
     * @param date
     * @return
     */
    @PostMapping("/queryUnqualified")
    public R queryUnqualified(String date){
        return R.ok().put("data", analysisService.queryUnqualified(date));
    }
    /**
     * 各乡镇突出问题点位整改表
     * @param date "yyyy-MM"
     * @return
     */
    @PostMapping("/queryZdwtzg")
    public R queryMonthlySummaryPointRectify(String date){
        List<MonthlySummaryPointRectify> monthlySummaryPointRectifies = analysisService.monthlySummaryPointRectify(date);
        return R.ok().put("data", monthlySummaryPointRectifies);
    }

    /*
    * 重点问题专项统计
    * */
    @PostMapping("/querySpecial")
    public R querySpecial(@RequestBody SpecialParam specialParam){
        List<SpecialEntity> specialEntities = analysisService.querySpecial(specialParam);
        return R.ok().put("data",specialEntities);
    }

    /**
     * 公厕管护问题
     * @param date
     * @return
     */
    @PostMapping("/queryToilets")
    public R queryToilets(String date){
        return R.ok().put("data", analysisService.queryToilets(date));
    }

    /**
     * 查询问题日期 date yyyy-mm
     * @return
     */
    @RequestMapping("/queryDate")
    public R queryDate(String date){
        List<WtDateEntity> wtDates = analysisService.queryDate(date);
        return R.ok().put("data", wtDates);
    }

    /**
     * 按月查大集数据
     * @param date yyyy-mm
     * @return
     */
    @PostMapping("/getDjByMon")
    public R getDjByMon(String date){
        List<PointRecordEntity> pointRecordEntities = analysisService.getDjByMon(date);
        return R.ok().put("data",pointRecordEntities);
    }

    /**
     * 查询日志内容
     * @param date
     * @param type 1 查询 1环境整治考核 3公厕管护考核 7垃圾暂存点   2 查询 6农村大集
     * @return
     */
    @PostMapping("/queryLogByCun")
    public R queryLogByCun(String date,Integer type){
        List<HjzzLogEntity> hjzzLogEntities = analysisService.queryLogByCun(date,type);
        return R.ok().put("data",hjzzLogEntities);
    }

    /*
    * 查询人员每日巡查村 参数 date yyyy-mm
    * */
    @RequestMapping("/queryCunByDate")
    public R queryCunByDate(String date){
        List<PatrolEntity> patrolEntities = analysisService.queryCunByDate(date);
        return R.ok().put("data",patrolEntities);
    }

    /**
     * 镇级问题数量统计
     * @return
     */
    @RequestMapping("/queryTownProblem")
    public R queryTownProblem(){
        List<TownProblemCountEntity> townProblemCounts = analysisService.queryTownProblem();
        return R.ok().put("data", townProblemCounts);
    }

    /**
    * 突出问题台账 加 图片  参数 date yyyy-mm type 1 突破问题 2 私搭乱建  3 污水问题
    * */
    @RequestMapping("/queryTz")
    public R queryTz(String date,Integer type){
        List<WttzEntity> wttzEntities = analysisService.queryTz(date,type);
        return R.ok().put("data",wttzEntities);
    }

    /**
     * 巡查日志和整改情况
     * @param date
     * @param type 2 巡查 3 完成
     * @return
     */
    @RequestMapping("/queryXczg")
    public R queryXczg(String date,Integer type){
        List<JournalEntity> journalEntities = enviorSupvsService.queryJournal(date,type);
        return R.ok().put("data",journalEntities);
    }

    /**
     *查询未整改情况表
     * @param reportDto
     * @return
     */
    @RequestMapping("/queryWzg")
    public R queryWzg(ReportDto reportDto){
        List<TownProblemCountEntity> countEntities = analysisService.queryWzg(reportDto);
        return R.ok().put("data",countEntities);
    }

    /**
     * 挂账月数统计接口
     * @param date yyyy-mm-dd
     * @return
     */
    @PostMapping("/getOnAccountDeduction")
    public R getOnAccountDeduction(String date){
        List<OnAccountDeductionEntity> onAccountDeductionEntities = analysisService.getOnAccountDeduction(date);
        return R.ok().put("data",onAccountDeductionEntities);
    }

    @PostMapping("/getOnAccountByDate")
    public R getOnAccountByDate(String date,Integer type){
        return R.ok().put("data", analysisService.getOnAccountByDate(date, type));
    }
    /**
     * 查询日志内容
     * @param date
     * @param type 1 查询 1环境整治考核 3公厕管护考核 7垃圾暂存点   2 查询 6农村大集
     * @return
     */
    @PostMapping("getDayLogByCun")
    public R getDayLogByCun(String date,Integer type){
        List<HjzzLogEntity> hjzzLogEntities = analysisService.getDayLogByCun(date,type);
        return R.ok().put("data", hjzzLogEntities);
    }

    /**
     * 各乡镇未处理情况表
     * @param date yyyy-mm
     * @return
     */
    @PostMapping("/getWzgqk")
    public R getWzgqk(String date){
        List<WzgqkEntity> wzgqkEntities = analysisService.getWzgqk(date);
        return R.ok().put("data",wzgqkEntities);
    }
}
